
public class Expression {

	ConditionalAndExpr cond;
	Expression expression;
	int op = Type.LO;

	public Expression() {

	}

	public Expression(ConditionalAndExpr cond, Expression expression) {
		super();
		this.cond = cond;
		this.expression = expression;
	}

	public void check() throws SemanticException {
		cond.check();
		if (expression != null)
			expression.check();

		checkType();
		// check same type and this stuff
	}

	/**
	 * Returns the type of the expression, or throws an exception if types of
	 * sub expression doesn't match
	 */
	public int checkType() throws SemanticException {
		if (expression != null) {
			if (cond.checkType() != Type.BL
					|| expression.checkType() != Type.BL)
				throw new SemanticException(
						"Types of expression doesn't match: "
								+ cond.checkType() + " , "
								+ expression.checkType());
			return Type.BL;
		}

		return cond.checkType();

	}

	public String toString() {
		String ret = "Expression\n";
		String s = "";
		if (expression != null)
			s += expression.toString();
		s += cond.toString();
		for (String st : s.split("\n"))
			ret += "| " + st + "\n";
		return ret;
	}

}
